package com.zrrd.straw1.service.impl;

import lombok.Data;

@Data
public class ServiceException extends RuntimeException{
    // Alt + insert -> Constructor
    private int code = 500 ; //服务器内部错误

    public ServiceException(int code) {
        this.code = code;
    }
    public ServiceException(String message, int code) {
        super(message);
        this.code = code;
    }
    public ServiceException(String message, Throwable cause, int code) {
        super(message, cause);
        this.code = code;
    }
    public ServiceException(Throwable cause, int code) {
        super(cause);
        this.code = code;
    }
    public ServiceException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, int code) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.code = code;
    }

    public static ServiceException invalidRequest( String message ){
        return new ServiceException(message, 400);
    }
    //2.404 : 用户请求一个不存的数据，服务器没有相应操作
    public static ServiceException notFound(String message ){
        return new ServiceException(message, 404);
    }
    //3.410 : 用户请求的资源已被永久删除，且不会再得到
    public static ServiceException gone(String message){
        return new ServiceException(message , 410);
    }
    //4.422 : 用户创建一个对象时，发生一个验证错误
    public static ServiceException unprocesableEntity(String message){
        return new ServiceException( message,422);
    }
    //5.500 : 服务器内部逻辑错误
    public static ServiceException busy(){
        return new ServiceException("数据库繁忙,请稍等..",500);
    }
}